﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using DBUtility;
using CommonFunc;

public partial class Control_NewsSmallList : System.Web.UI.UserControl
{
    #region 封装字段
    private int topNum;
    private int classID;
    private string filterExpression;
    private int subStrNum;

    public int TopNum
    {
        get { return topNum; }
        set { topNum = value; }
    }

    public int ClassID
    {
        get { return classID; }
        set { classID = value; }
    }

    public string FilterExpression
    {
        get { return filterExpression; }
        set { filterExpression = value; }
    }

    public int SubStrNum
    {
        get { return subStrNum; }
        set { subStrNum = value; }
    }
    #endregion

    MODEL.NewsClass MNC = new MODEL.NewsClass();
    MODEL.NewsClass _MNC = new MODEL.NewsClass();

    BLL.NewsClass BNC = new BLL.NewsClass();

    protected void Page_Load(object sender, EventArgs e)
    {
        ControlDataInit();
    }


    #region ControlDataInit
    protected void ControlDataInit()
    {
        try
        {
            string SQLstr_News;

            if (this.TopNum != 0)
            {
                SQLstr_News = "SELECT TOP " + this.TopNum + " * FROM [News] WHERE [News_IsLock]=false AND [News_IsDel]=false ";
            }
            else
            {
                SQLstr_News = "SELECT TOP 8 * FROM [News] WHERE [News_IsLock]=false AND [News_IsDel]=false ";
            }

            if (this.ClassID != 0)
            {
                MNC.NC_ID = Convert.ToInt32(this.ClassID);

                _MNC = BNC.GetDataByID(MNC);

                SQLstr_News += "AND [News_ClassCode] LIKE '" + _MNC.NC_ClassCode + "%' ";
            }

            if (this.FilterExpression != null)
            {
                SQLstr_News += "AND " + this.FilterExpression + " ";
            }

            SQLstr_News += "ORDER BY [News_DateTime] DESC";

            DataTable DT_News = AccHelper.GetDataTable(SQLstr_News);

            RPT_NewList1.DataSource = DT_News.DefaultView;

            RPT_NewList1.DataBind();
        }
        catch (Exception ex)
        {
            LB_NewsList_Small.Text = ex.Message;
        }
    }
    #endregion


    #region 格式化文章标题
    protected string FormatNewsTitle(object _Title)
    {
        string NewsTitle = Convert.ToString(_Title);

        if (this.SubStrNum == 0)
        {
            return NewsTitle;
        }
        else
        {
            if (NewsTitle.Length > this.SubStrNum)
            {
                return CommonFunction.SubStr(NewsTitle, this.SubStrNum, " …");
            }
            else
            {
                return NewsTitle;
            }
        }
    }
    #endregion
}
